
export const getDayListAgo = (num = 5, initDay = Date.now()) => {
  const start = new Date(initDay)

  return Array(num)
    .fill(null)
    .map((_, i) => {
      const t = new Date(start - i * 1000 * 60 * 60 * 24)
      const arr = [t.getFullYear(),
        '0' + (t.getMonth() + 1).toString().substr(-2, 2),
        t.getDate().toString().padStart(2, '0')]
      return arr.join('-')
    })
}

export const format = (timestamp) => {
  if (timestamp === undefined) {
    return ''
  }
  try {
    // eslint-disable-next-line no-debugger
    const t = new Date(timestamp)

    const arr = [
      // t.getFullYear(),
      '0' + (t.getMonth() + 1).toString().substr(-2, 2) + '月',
      t.getDate().toString().padStart(2, '0') + '日',
      t.getHours().toString().padStart(2, '0') + '点',
      t.getMinutes().toString().padStart(2, '0') + '分']
    return arr.join('-')
  } catch {
    return '未知'
  }
}
